//
//  ShowMoodViewController.m
//  Diary
//
//  Created by lanou3g on 15/12/22.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "ShowMoodViewController.h"
#import "MoodWebView.h"
#import "MBProgressHUD.h"
#import "Reachability.h"
#import "UMSocial.h"
#import "UIImageView+WebCache.h"
#import "JokeDataManager.h"
#import "Model.h"
#import "DataHandel.h"
#import "MBProgressHUD.h"
@interface ShowMoodViewController ()<UIWebViewDelegate,UMSocialUIDelegate>

@end

@implementation ShowMoodViewController


-(void)loadView{

       
    self.moodwebview = [[MoodWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.moodwebview;

}



- (void)viewDidLoad {
    [super viewDidLoad];
   

    self.moodwebview.delegate  = self;
    
   
    //网络判断
    [self judegNet];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
    [self.moodwebview loadRequest:request];
   
//
//    //[reach isReachableViaWWAN]
//    //[reach isReachable]
//    if ([reach isReachable]) {
//        //取消转圈
//        [MBProgressHUD hideHUDForView:self.moodwebview animated:YES];
//       
//        
//    }
//    
//   else if ([reach isReachableViaWWAN]) {
//        //取消转圈
//        [MBProgressHUD hideHUDForView:self.moodwebview animated:YES];
//
//    }
//    
//    else{
//        //网络请求之前
//      //  [MBProgressHUD showHUDAddedTo:self.moodwebview animated:YES];
//        
//    }
    
    
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftItemAction:)];
    self.navigationItem.leftBarButtonItem = leftItem;

    
    
    //分享按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"分享2.png"] style:UIBarButtonItemStylePlain target:self action:@selector(sharedAction)];
    
}


#pragma mark -- 判断是否有网
-(void)judegNet{
    if(![[DataHandel sharedHandel]connectedToNetwork ])
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"网络连接失败,请查看网络是否连接正常！" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        
    }else{
        
        //网络请求之前
        [MBProgressHUD showHUDAddedTo:self.moodwebview animated:YES];
        //根据网址加载webView
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
        [self.moodwebview loadRequest:request];
        //取消转圈
        [MBProgressHUD hideHUDForView:self.moodwebview animated:YES];

    }
    
}



#pragma mark -- 分享按钮点击
-(void)sharedAction{
   
     NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_firstImg]];
    
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:nil
                                      shareText:_source
                                     shareImage:[UIImage imageWithData:data]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQQ,UMShareToQzone,UMShareToLWTimeline,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite,nil]
                                    delegate:self];
   

    //QQ好友
    [UMSocialData defaultData].extConfig.qqData.title = self.title;
    
    [UMSocialData defaultData].extConfig.qqData.url = self.url;
    //QQ空间
    [UMSocialData defaultData].extConfig.qzoneData.title = self.title;
    
    [UMSocialData defaultData].extConfig.qzoneData.url = self.url;
    
    //微信好友
    [UMSocialData defaultData].extConfig.wechatSessionData.url = self.url;
    
    [UMSocialData defaultData].extConfig.wechatSessionData.title = self.title;
    //微信朋友圈
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.url;
    
    [UMSocialData defaultData].extConfig.wechatTimelineData.title = self.title;
    //微信收藏
    [UMSocialData defaultData].extConfig.wechatFavoriteData.url = self.url;
    
    [UMSocialData defaultData].extConfig.wechatFavoriteData.title = self.title;
}



//返回首页事件
- (void)leftItemAction:(UIBarButtonItem *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
